import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

const routes: RouteRecordRaw[] = [
  { path: '/', redirect: '/login' },
  // 顶层页（与 /grades 同级）
  { path: '/login', name: 'login', component: () => import('@/views/LoginView.vue') },
  { path: '/home', name: 'home', component: () => import('@/views/HomeView.vue') },
  { path: '/erp', name: 'erp', component: () => import('@/views/ErpView.vue') },
  { path: '/shop', name: 'shop', component: () => import('@/views/ShopView.vue') },
  { path: '/gimini', name: 'gimini', component: () => import('@/views/GiminiView.vue') },
  { path: '/xwChat', name: 'xw-chat', component: () => import('@/views/XwChatView.vue') },
  {
    path: '/examOnline',
    name: 'examOnline',
    component: () => import('@/views/hundred/education/ExamOnlineView.vue'),
  },
  {
    path: '/examAdmin',
    name: 'examAdmin',
    component: () => import('@/views/hundred/education/ExamOnlineAdminView.vue'),
  },
  {
    path: '/navigationMain',
    name: 'navigationMain',
    component: () => import('@/views/hundred/NavigationMainPageView.vue'),
  },

  // About 及其子路由（alias 兼容 AboutView 中的绝对路径跳转）
  {
    path: '/about',
    name: 'about',
    component: () => import('@/views/AboutView.vue'),
    children: [
      {
        path: 'user',
        name: 'about-user',
        alias: '/user',
        component: () => import('@/components/UserView.vue'),
      },
      {
        path: 'urlBookMarkView',
        name: 'about-urlBookMark',
        alias: '/urlBookMarkView',
        component: () => import('@/components/UrlBookMarkView.vue'),
      },
      {
        path: 'chatUser',
        name: 'about-chatUser',
        alias: '/chatUser',
        component: () => import('@/components/ChatUserView.vue'),
      },
      {
        path: 'fileUpDown',
        name: 'about-fileUpDown',
        alias: '/fileUpDown',
        component: () => import('@/components/FileUpDownView.vue'),
      },
      {
        path: 'fileDsUpDown',
        name: 'about-fileDsUpDown',
        alias: '/fileDsUpDown',
        component: () => import('@/components/FileDsUpDownView.vue'),
      },
      {
        path: 'chatView',
        name: 'about-chatView',
        alias: '/chatView',
        component: () => import('@/components/chat/ChatView.vue'),
      },
      {
        path: 'chatMqttView',
        name: 'about-chatMqttView',
        alias: '/chatMqttView',
        component: () => import('@/components/chat/ChatMqttView.vue'),
      },
      {
        path: 'chatBootView',
        name: 'about-chatBootView',
        alias: '/chatBootView',
        component: () => import('@/components/chat/ChatBootView.vue'),
      },
      {
        path: 'dsSse',
        name: 'about-dsSse',
        alias: '/dsSse',
        component: () => import('@/components/DsSseView.vue'),
      },
      // 以下 6 个为 AboutView 中存在跳转但暂未找到组件的功能位，先占位
      {
        path: 'timeChange',
        name: 'about-timeChange',
        alias: '/timeChange',
        component: () => import('@/components/TimeChangeView.vue'),
      },
      {
        path: 'enDecode',
        name: 'about-enDecode',
        alias: '/enDecode',
        component: () => import('@/components/EnDecodeView.vue'),
      },
      {
        path: 'four',
        name: 'about-four',
        alias: '/four',
        component: () => import('@/components/FourView.vue'),
      },
      {
        path: 'haloDemo',
        name: 'about-haloDemo',
        alias: '/haloDemo',
        component: () => import('@/components/HaloDemo.vue'),
      },
      {
        path: 'vueTest1',
        name: 'about-vueTest1',
        alias: '/vueTest1',
        component: () => import('@/components/VueTest1.vue'),
      },
      {
        path: 'vueTest2',
        name: 'about-vueTest2',
        alias: '/vueTest2',
        component: () => import('@/components/VueTest2.vue'),
      },
    ],
  },
  // 原有 /grades 管理分组
  {
    path: '/grades',
    component: () => import('@/views/hundred/GradesAdminLayout.vue'),
    children: [
      { path: '', name: 'grades-home', redirect: { name: 'grades-students' } },
      {
        path: 'students',
        name: 'grades-students',
        component: () => import('@/views/hundred/grades/StudentAdminView.vue'),
      },
      {
        path: 'teachers',
        name: 'grades-teachers',
        component: () => import('@/views/hundred/grades/TeacherAdminView.vue'),
      },
      {
        path: 'departments',
        name: 'grades-departments',
        component: () => import('@/views/hundred/grades/DepartmentAdminView.vue'),
      },
      {
        path: 'majors',
        name: 'grades-majors',
        component: () => import('@/views/hundred/grades/MajorAdminView.vue'),
      },
      {
        path: 'classes',
        name: 'grades-classes',
        component: () => import('@/views/hundred/grades/ClazzAdminView.vue'),
      },
      {
        path: 'courses',
        name: 'grades-courses',
        component: () => import('@/views/hundred/grades/CourseAdminView.vue'),
      },
      {
        path: 'terms',
        name: 'grades-terms',
        component: () => import('@/views/hundred/grades/TermAdminView.vue'),
      },
      {
        path: 'offerings',
        name: 'grades-offerings',
        component: () => import('@/views/hundred/grades/OfferingAdminView.vue'),
      },
      {
        path: 'score-items',
        name: 'grades-score-items',
        component: () => import('@/views/hundred/grades/ScoreItemAdminView.vue'),
      },
      {
        path: 'enrollments',
        name: 'grades-enrollments',
        component: () => import('@/views/hundred/grades/EnrollmentAdminView.vue'),
      },
      {
        path: 'appeals',
        name: 'grades-appeals',
        component: () => import('@/views/hundred/grades/AppealAdminView.vue'),
      },
      {
        path: 'publish',
        name: 'grades-publish',
        component: () => import('@/views/hundred/grades/ScorePublishView.vue'),
      },
    ],
  },

  { path: '/:pathMatch(.*)*', redirect: '/grades' },
]

const router = createRouter({
  history: createWebHistory(),
  routes,
})

export default router
